<html lang="en">
<head>
    <title>推荐头条管理</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery.form.js"></script>
    <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
    <script>
        $(function () {
            //配置图片上传路径
            var ck=CKEDITOR.replace( 'content', {
                filebrowserBrowseUrl: '图片服务器',
                filebrowserUploadUrl: '/images/upload.do'
            });

            //图片更换回显
            $('#editForm input[name="file"]').change(function () {
                $('#editForm img').attr('src',window.URL.createObjectURL(this.files[0]));
            });

            $(".inputBtn").click(function () {
                $("#editForm")[0].reset();
                $('#editForm img').attr('src','');
                ck.setData('');
                var json = $(this).data("json");
                if(json){
                    var catalogBigId = json.lcdId;
                    $.get("/headlineCommend/getCatalogBigId.do",{cbId:catalogBigId},function (data) {
                        var tcbId=data.lmTicketCatalogBig.id;
                        if(tcbId){
                            console.log(tcbId);
                            $("#editForm select[name='lcdId']").val(tcbId);
                        }
                    });
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='coverURL']").val(json.coverURL);
                    $("#editForm input[name='grade']").val(json.grade);
                    $("#editForm input[name='childPrice']").val(json.childPrice);
                    $("#editForm input[name='adultPrice']").val(json.adultPrice);
                    $("#editForm input[name='location']").val(json.location);
                    $("#imgCoverUrl").attr("src",json.coverURL);
                    $("#editForm select[name='discount']").val(json.discount);


                    //内容回显
                    $.get("/headlineCommend/getContentById.do",{id:json.id},function (data) {
                        //console.log(data);
                        ck.setData(data.content);
                    })

                }
                $("#editModal").modal("show");
            });

            $(".submitBtn").click(function () {
                //如果ckeditor无法自动给textarea赋值,手动调用方法赋值
                var content = ck.getData();
                $('#content').html(content);

                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示","操作成功",function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("温馨提示",data.msg);
                    }
                })
            });
        });
    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="headlineCommend">

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">添加景点门票</h1>
                </div>
            </div>
            <div class="form-group">
                <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 添加</button>
            </div>

            <table class="table table-striped table-hover" >
                <thead>
                    <tr>
                        <th>推荐页面唯一头条</th>
                        <th>图片</th>
                        <th>评分</th>
                        <th>儿童票价</th>
                        <th>成人票</th>
                        <th>位置</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <#list result as entity>
                   <tr>
                       <td>${entity.title!}</td>
                       <td><img src="${entity.coverURL!}" width="150px"></td>
                       <td>${entity.grade!}</td>
                       <td>${entity.childPrice!}</td>
                       <td>${entity.adultPrice!}</td>
                       <td>${entity.location!}</td>
                       <td>
                           <a href="javascript:;" class="btn btn-success inputBtn" data-json='${entity.jsonString}'>修改</a>
                       </td>
                   </tr>
                </#list>
            </table>
        </div>
    </div>
</div>


<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/headlineCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" value="" name="id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" value="" placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="" width="200px" id="imgCoverUrl">
                            <input type="file" name="file">
                            <input type="hidden" name="coverURL" value="">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">评分：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="grade" value="" placeholder="请输入评分">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">儿童票：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="childPrice" value="" placeholder="请输入儿童价">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">成人票：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="adultPrice" value="" placeholder="请输入成人价">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">位置：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="location" value="" placeholder="请输入景点位置">
                        </div>
                    </div>

                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属分类：</label>
                        <div class="col-sm-6">
                            <select id="lcdId" name="lcdId" class="form-control">
                                <option value="-1">--请选择--</option>
                                    <#list lcDetails as s>
                                        <option value="${s.id}">${s.name}</option>
                                    </#list>
                            </select>
                        </div>
                    </div>

                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">是否头条推荐：</label>
                        <div class="col-sm-6">
                            <select name="discount" class="form-control" id="discount">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>

                    <textarea name="landmarkContent.content" id="content" rows="10" cols="80"></textarea>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary submitBtn">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>